//
//  BaseVC.swift
//  VC
//
//  Created by mini on 2025/4/28.
//

import Foundation

class BaseVC: UIViewController {

  var dismissBlock:(()->())?

    // MARK: - lazy
    lazy var viewBg: UIImageView = {
        let view = UIImageView.init()
        view.widthHeight = XY(SCREEN_WIDTH, SCREEN_HEIGHT)
        view.leftTop = XY(0, 0)
        view.backgroundColor = COLOR_BACKGROUND
        return view
    }()
    
    // MARK: - viewDidLoad
    override func viewDidLoad() {
        super.viewDidLoad()
        hiddenNavigationBar()
        // 增加侧滑
//        if(self.navigationController?.responds(to: #selector(getter: UINavigationController.interactivePopGestureRecognizer)) ?? false){
//            self.navigationController?.interactivePopGestureRecognizer?.delegate = nil
//        }
        // 禁用侧滑返回
        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
        // 设置 contentInsetAdjustmentBehavior
        if #available(iOS 11.0, *) {
            //self.contentInsetAdjustmentBehavior = .never
        } else {
            self.automaticallyAdjustsScrollViewInsets = false
        }
        // 背景颜色
        self.view.backgroundColor = .white
        self.view.insertSubview(self.viewBg, at: 0)
    }
    
    // MARK: - viewDidAppear
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        hiddenNavigationBar()
    }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        hiddenNavigationBar()
        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = GlobalMethod.canLeftSlide();
        #if DEBUG
        print("current vc - \(String(describing: type(of: self)))")
        #endif
    }
    
    func hiddenNavigationBar() {
        // 设置隐藏导航栏
        self.navigationController?.navigationBar.isHidden = true
    }
    
    // MARK: - viewWillDisappear
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.view.endEditing(true)
    }
    
    // MARK: - dealloc
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    
    // MARK: - 设置状态栏
    override var preferredStatusBarStyle: UIStatusBarStyle{
        return GlobalData.sharedInstance.statusBarStyle
    }
    
    override var prefersStatusBarHidden: Bool{
        return GlobalData.sharedInstance.statusHidden
    }
}
